﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFIDA.U9.SM.Ship;
using UFIDA.U9.PM.PO;
using UFSoft.UBF.PL;
using UFIDA.U9.PM.Rcv;
using UFIDA.U9.SM.RMA;
using UFIDA.U9.SM.SO;
using UFIDA.U9.CBO.SCM.Customer;


namespace UFIDA.U9.Cust.Cli.PlugBE
{
    /// <summary>
    /// 玖源机械项目
    /// 收货单
    /// 收货单审核时写入批号备注
    /// </summary>
    class JYJXRcvUpdatedExtend : IEventSubscriber
    {
        //配置XX.sub.xml文件放置到portal/bin下，dll文件放置到portal/ApplicationServer/Libs下
        public void Notify(params object[] args)
        {
            if (args != null && args.Length != 0 && args[0] is EntityEvent)
            {
                BusinessEntity.EntityKey key = ((EntityEvent)args[0]).EntityKey;
                Receivement rcv = key.GetEntity() as Receivement;
                if (rcv == null)
                    return;
                //收货单审核时写入批号备注
                if (rcv.Status == RcvStatusEnum.Closed &&
                    rcv.OriginalData.Status == RcvStatusEnum.Approving)
                {
                    using (ISession session = Session.Open())
                    {
                        foreach(RcvLine line in rcv.RcvLines)
                        {
                            if (line.InvLot == null) continue;
                            line.InvLot.DescFlexSegments.PubDescSeg2 = line.DescFlexSegments.PubDescSeg2;
                        }

                        session.Commit();
                    }
                  
                }
            }
        }

     
    }
}
